﻿using Core;

namespace g_gongjianta
{
    public abstract class AbstractSkillEvent : Core.Component, ISkillEvent
    {
        public long SkillSrl { get; private set; }
        public TblSkill.Conf SkillConf { get; private set; }

        public int Duration { get; protected set; }
        public bool IsComplete { get; protected set; }

        public virtual void Awake(long t1, TblSkill.Conf t2)
        {
            SkillSrl = t1;
            SkillConf = t2;

            Duration = SkillConf.Duration;
        }

        protected int startFrame;
        public virtual void Start()
        {
            startFrame = SysTime.FrameCount;
            IsComplete = false;
        }

        public virtual void Tick()
        {
            var frame = SysTime.FrameCount - startFrame;

            if (frame >= Duration)
            {
                IsComplete = true;
            }
        }

        public virtual void Finish()
        {
            IsComplete = true;
        }

        public virtual void Interrupt()
        {
            IsComplete = true;
        }
    }

    public abstract class AbstractSkillEvent<T> : AbstractSkillEvent
        where T : TblSkill.SkillEvt
    {
        public T EvtConf { get; private set; }

        public virtual void Awake(long t1, TblSkill.Conf t2, T t3)
        {
            base.Awake(t1, t2);

            EvtConf = t3;
        }

        public override void Dispose()
        {
            if (IsDisposed) return;
            base.Dispose();
        }
    }
}
